<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>数据脱敏组件 | SPEED 团队企业级中台组件</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="$withBase(&#39;/avatar.png&#39;)">
    <meta name="description" content="">
    
    <link rel="preload" href="/assets/css/0.styles.4a390c75.css" as="style"><link rel="preload" href="/assets/js/app.9e59f384.js" as="script"><link rel="preload" href="/assets/js/2.61252cf6.js" as="script"><link rel="preload" href="/assets/js/9.be610aef.js" as="script"><link rel="prefetch" href="/assets/js/10.47abf4f2.js"><link rel="prefetch" href="/assets/js/11.f25fa446.js"><link rel="prefetch" href="/assets/js/12.b817a6b9.js"><link rel="prefetch" href="/assets/js/13.a9ff20a6.js"><link rel="prefetch" href="/assets/js/14.5f5c406e.js"><link rel="prefetch" href="/assets/js/3.a4b7a9d2.js"><link rel="prefetch" href="/assets/js/4.8bbc0415.js"><link rel="prefetch" href="/assets/js/5.64a3d90d.js"><link rel="prefetch" href="/assets/js/6.65875694.js"><link rel="prefetch" href="/assets/js/7.c347ceab.js"><link rel="prefetch" href="/assets/js/8.07cb2ef7.js">
    <link rel="stylesheet" href="/assets/css/0.styles.4a390c75.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/avatar.png" alt="SPEED 团队企业级中台组件" class="logo"> <span class="site-name can-hide">SPEED 团队企业级中台组件</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>业务中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/业务中台组件/登录认证授权组件.html" class="sidebar-link">登录认证授权组件</a></li><li><a href="/业务中台组件/数据脱敏组件.html" class="active sidebar-link">数据脱敏组件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/业务中台组件/数据脱敏组件.html#_1-引入" class="sidebar-link">1.引入</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/数据脱敏组件.html#_2-配置数据脱敏注解" class="sidebar-link">2.配置数据脱敏注解</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/数据脱敏组件.html#_3-调用测试" class="sidebar-link">3.调用测试</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/数据脱敏组件.html#_4-输出" class="sidebar-link">4.输出</a></li><li class="sidebar-sub-header"><a href="/业务中台组件/数据脱敏组件.html#_5-返回" class="sidebar-link">5.返回</a></li></ul></li><li><a href="/业务中台组件/OBS 对象存储组件.html" class="sidebar-link">OBS 对象存储组件</a></li><li><a href="/业务中台组件/邮件发送组件.html" class="sidebar-link">邮件发送组件</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>数据中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/数据中台组件/钉钉告警组件.html" class="sidebar-link">钉钉告警组件</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="数据脱敏组件"><a href="#数据脱敏组件" class="header-anchor">#</a> 数据脱敏组件</h1> <h2 id="_1-引入"><a href="#_1-引入" class="header-anchor">#</a> 1.引入</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>tlgen<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>desensitization<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">2022.5</span><span class="token number">.19</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h2 id="_2-配置数据脱敏注解"><a href="#_2-配置数据脱敏注解" class="header-anchor">#</a> 2.配置数据脱敏注解</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>springbootdesensitization<span class="token punctuation">.</span>domain<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>springbootdesensitization<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Sensitive<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>springbootdesensitization<span class="token punctuation">.</span>desensitization<span class="token punctuation">.</span>SensitiveStrategy<span class="token punctuation">;</span>
import lombok<span class="token punctuation">.</span>Data<span class="token punctuation">;</span>
import lombok<span class="token punctuation">.</span>ToString<span class="token punctuation">;</span>

<span class="token variable">@Data</span>
<span class="token variable">@ToString</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 真实姓名
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@Sensitive</span><span class="token punctuation">(</span>strategy <span class="token operator">=</span> SensitiveStrategy<span class="token punctuation">.</span><span class="token constant">USERNAME</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token builtin">String</span> realName<span class="token punctuation">;</span>
    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 地址
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@Sensitive</span><span class="token punctuation">(</span>strategy <span class="token operator">=</span> SensitiveStrategy<span class="token punctuation">.</span><span class="token constant">ADDRESS</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token builtin">String</span> address<span class="token punctuation">;</span>
    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 电话号码
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@Sensitive</span><span class="token punctuation">(</span>strategy <span class="token operator">=</span> SensitiveStrategy<span class="token punctuation">.</span><span class="token constant">PHONE</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token builtin">String</span> phoneNumber<span class="token punctuation">;</span>
    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 身份证号码
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@Sensitive</span><span class="token punctuation">(</span>strategy <span class="token operator">=</span> SensitiveStrategy<span class="token punctuation">.</span><span class="token constant">ID_CARD</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token builtin">String</span> idCard<span class="token punctuation">;</span>

<span class="token punctuation">}</span>

</code></pre></div><h2 id="_3-调用测试"><a href="#_3-调用测试" class="header-anchor">#</a> 3.调用测试</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>springbootdesensitization<span class="token punctuation">.</span>controller<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>springbootdesensitization<span class="token punctuation">.</span>domain<span class="token punctuation">.</span>Person<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>slf4j<span class="token punctuation">.</span>Logger<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>slf4j<span class="token punctuation">.</span>LoggerFactory<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>GetMapping<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RequestMapping<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RestController<span class="token punctuation">;</span>

<span class="token variable">@RestController</span>
<span class="token variable">@RequestMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/hello&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HelloController</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> static final Logger <span class="token constant">LOGGER</span> <span class="token operator">=</span> LoggerFactory<span class="token punctuation">.</span>getLogger<span class="token punctuation">(</span>HelloController<span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token variable">@GetMapping</span>
    <span class="token keyword">public</span> Person hello<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Person person <span class="token operator">=</span> <span class="token keyword">new</span> Person<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        person<span class="token punctuation">.</span>setRealName<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;五象大厦&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        person<span class="token punctuation">.</span>setPhoneNumber<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;13617786070&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        person<span class="token punctuation">.</span>setAddress<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;广西五象大厦...&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        person<span class="token punctuation">.</span>setIdCard<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;4527246000718101600&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token constant">LOGGER</span><span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;人物信息: {}&quot;</span></span><span class="token punctuation">,</span> person<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> person<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>

</code></pre></div><h2 id="_4-输出"><a href="#_4-输出" class="header-anchor">#</a> 4.输出</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>人物信息<span class="token operator">:</span> Person<span class="token punctuation">(</span>realName<span class="token operator">=</span>五象大厦<span class="token punctuation">,</span> address<span class="token operator">=</span>广西五象大厦<span class="token operator">...</span><span class="token punctuation">,</span> phoneNumber<span class="token operator">=</span><span class="token number">13617786070</span><span class="token punctuation">,</span> idCard<span class="token operator">=</span><span class="token number">4527246000718101600</span><span class="token punctuation">)</span>

</code></pre></div><h2 id="_5-返回"><a href="#_5-返回" class="header-anchor">#</a> 5.返回</h2> <div class="custom-block tip"><p class="custom-block-title">案例测试</p> <p>http://localhost:8080/hello</p> <p>返回 JSON 实现数据脱敏效果</p></div> <div class="language-ruby extra-class"><pre class="language-ruby"><code><span class="token punctuation">{</span><span class="token string-literal"><span class="token string">&quot;realName&quot;</span></span><span class="token symbol">:&quot;五*大厦&quot;</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;address&quot;</span></span><span class="token symbol">:&quot;广西五****厦.****&quot;</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;phoneNumber&quot;</span></span><span class="token symbol">:&quot;136****6070&quot;</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;idCard&quot;</span></span><span class="token symbol">:&quot;4527****01600&quot;</span><span class="token punctuation">}</span>
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/业务中台组件/登录认证授权组件.html" class="prev">
        登录认证授权组件
      </a></span> <span class="next"><a href="/业务中台组件/OBS 对象存储组件.html">
        OBS 对象存储组件
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.9e59f384.js" defer></script><script src="/assets/js/2.61252cf6.js" defer></script><script src="/assets/js/9.be610aef.js" defer></script>
  </body>
</html>
